//do /Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Code_JPEmicro/Regression_Inattention_Match_Pair_Day_vPaper_08072018_replication.do 
pause on
set more off


global pathname="/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Data/Pair_matching_estimator"
global pathresults="/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results_Estimation/Pair_matching"

/*
Dependencies:
	do \\...\Select_Available_Day_Pair_Match_vPaper_08072018.do
	do \\...\Select_Dominated_Week_Pair_Match_vPaper_08072018.do 
	do \\...\Prep_Reg_Inattention_Match_Pair_vPaper_08072018.do 

Non-Parametric Regressions: 
	The proportion by "sum pair_high_ee" is the fraction of consumers
	that chose the high energy efficiency (ee) option during a week with 
	a dominated price event (dominated_week==1). The stock-out effect is controlled
	by the variable: avail_day_#_pair==1
	 avail_day_0_pair: both products where available in the same zip code the same day
	 avail_day_1_pair: store availability is one day after/before an observed sales
	 avail_day_2_pair: store availability is two days after/before an observed sales
	 avail_day_4_pair: store availability is four days after/before an observed sales
	 etc...
	  
	To restrict the sample to products with only one store by zip code: nb_store==1

	One minus sum pair_high_ee corresponds to the proportion of innatentive consumers.

Linear Probability Model:	
	
*/

		    
local sample_dataset="day_zip_size2only"

log using $pathresults/Run_Regression_Inattention_pairs_matched_2_size2only_manual_check_YQ_SH_EEGap_`sample_dataset'_08072018.txt, replace

//This is the sample of pairs that were manually verified by SH RA.
//The choice set are created to impute availability at the zipcode and day level.
//Zipcode with multiple stores can be dropped as a senstivity analysis. 
 
*use $pathname\refrigerators\pairs_matched_2_size2only_manual_check_YQ_SH_`sample_dataset'_reg_ready, clear
use $pathname/pairs_matched_2_size2only_manual_check_YQ_SH_`sample_dataset'_reg_ready, clear 
  
//----------------------------------------------------------------------------------------------------------------------------
//Summary Statistics
//----------------------------------------------------------------------------------------------------------------------------	
    
	sum delta_kwh, detail                        
    sum delta_elec_cost_cty, detail
	sum delta_price, detail 
	sum delta_price if dominated_week==1  
	sum delta_s_estar 
	sum delta_cfa 
	sum delta_rebate_utility

pause

//----------------------------------------------------------------------------------------------------------------------------
//Non-Parametric Regressions: estimate the share of consumers that
//choose the most energy efficient option in a pair.
//----------------------------------------------------------------------------------------------------------------------------	
		
// Most conservative model: sales on the same day, only in zip codes with one store. 
//                          The two products were then on sales on the same day. 
		sum pair_high_ee if avail_day_0_pair==1 & dominated_week==1 & nb_store==1
	    sum delta_price if avail_day_0_pair==1 & dominated_week==1 & nb_store==1
// Sensitivity with respect to product availability	
		sum pair_high_ee if avail_day_1_pair==1 & dominated_week==1 & nb_store==1
		sum delta_price if avail_day_1_pair==1 & dominated_week==1 & nb_store==1
		
		sum pair_high_ee if avail_day_2_pair==1 & dominated_week==1  & nb_store==1
		sum delta_price if avail_day_2_pair==1 & dominated_week==1  & nb_store==1
		
		sum pair_high_ee if avail_day_4_pair==1 & dominated_week==1  & nb_store==1
		sum delta_price if avail_day_4_pair==1 & dominated_week==1  & nb_store==1
		
		sum pair_high_ee if avail_day_6_pair==1 & dominated_week==1  & nb_store==1
		sum delta_price if avail_day_6_pair==1 & dominated_week==1  & nb_store==1
		
		sum pair_high_ee if avail_day_12_pair==1 & dominated_week==1  & nb_store==1
		sum delta_price if avail_day_12_pair==1 & dominated_week==1  & nb_store==1
		
		sum pair_high_ee if avail_day_24_pair==1 & dominated_week==1  & nb_store==1
		sum delta_price if avail_day_24_pair==1 & dominated_week==1  & nb_store==1
							

log close

